<?php
/**
 * Controller_Traffic
 *
 * Класс Controller_Traffic отвечает за обработку данных по перевозкам
 */
class Controller_Traffic extends Controller_Base {

	/**
	 * Выбор действия по URL
	 *
	 */
	public function action() {
		Service_Debug::setDebug();
		if(empty($this->arrRequest[1])) $this->actionIndex();
		else {
			$cityUrlHtm = Service_Escape::absolutelyEscapeString($this->arrRequest[1]);
			$cityUrl = str_replace('.htm', '', $cityUrlHtm);
			
			$objCity = new City();
			$objCity->find('first', array(
				'conditions' => "`city_url` = '" . $cityUrl . "'"
			));
			if ($objCity->id) $this->actionCity($objCity);
			else throw new Exception_SiteError('', 404);
		}
		
	}

	/**
	 * Выводит сводную страницу по направлениям перевозок
	 */
	public function actionIndex() {
		$objViewTraffic = new View_Traffic();
		$objCity = new City();
		$arrCities = $objCity->find('all', array(
			'conditions' => '`city`.`city_url` IS NOT NULL'		
		));
  	$this->showHeader();
	    $objViewTraffic->showList($arrCities);
		$this->showFooter();
	}
	
	/**
	 * Выводит страницу города в направлениях перевозок
	 * 
	 * @param City $objCity - объект города
	 */
	public function actionCity(City $objCity) {
		Service_Debug::setDebug();
		$cityName = $objCity->getField('city_name');
		$cityNameGenetive = Service_Declination::getGenitive($cityName);
		
		$objViewTraffic = new View_Traffic();
		$this->title = $objViewTraffic->getOneCityTitle($objCity);
		$this->pageHead = 'Грузоперевозки ' . $cityNameGenetive;
		$this->showHeader();
			echo $objViewTraffic->getOneCityFirstP($objCity);
		$this->showFooter();
	}

}
?>